package Conf;
import Exceptions.GeneralException;
import Exceptions.StrategoException;
import Logic.IPoint;
import Logic.Objects.Point;

public class LandBorders {
	public final static IPoint[] Player1 = {new Point(1,Consts.N-13),new Point(1,Consts.N-4), new Point(Consts.N-14,Consts.N-13),new Point(Consts.N-14,Consts.N-4)};
	public final static IPoint[] Player2 = {new Point(Consts.N-13,1),new Point(Consts.N-13,Consts.N-14), new Point(Consts.N-4,1),new Point(Consts.N-4,Consts.N-14)};
	public final static IPoint[] Player3 = {new Point(Consts.N-13,Consts.N-3),new Point(Consts.N-13,Consts.N), new Point(Consts.N-4,Consts.N-3),new Point(Consts.N-4,Consts.N)};
	public final static IPoint[] Player4 = {new Point(Consts.N-3,Consts.N-13),new Point(Consts.N-3,14), new Point(Consts.N,4),new Point(Consts.N,Consts.N-4)};	
	
	/*
	 * CheckPlayerBorders:
	 * 
	 * @return true if XY is in player Land. false otherwise.
	 * 
	 */
	public static boolean CheckPlayerBorders (int PlayerNum , int x, int y) {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			return false;
		IPoint[] player = null;
		switch (PlayerNum) {
			case 1: player = Player1; break;
			case 2: player = Player2; break;
			case 3: player = Player3; break;
			case 4: player = Player4; break;
		}
		if (x >= player[0].getX()-1 && x <= player[2].getX()+1)
			if (y >= player[0].getY()-1 && y <= player[1].getY()+1)
					return true;
		return false;
	}
	
	/*
	 * getBorders:
	 * 
	 * @return IPoint[] of player Land edges.
	 * 
	 */
	public static IPoint[] getBorders (int PlayerNum ) {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			return null;
		switch (PlayerNum) {
			case 1: return Player1; 
			case 2: return Player2;
			case 3: return Player3; 
			case 4: return Player4; 
		}	
		return null;
	}
	
	/*
	 * MaxY:
	 * 
	 * @return Integer of player Land Max Y edge.
	 * 
	 */
	public static int MaxY (int PlayerNum )  throws StrategoException {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			throw new GeneralException(GeneralException.GeneralExceptionType.NotValidPlayer);
		switch (PlayerNum) {
			case 1: return Math.max(Player1[0].getY() , Player1[1].getY());
			case 2: return Math.max(Player2[0].getY() , Player2[1].getY());
			case 3: return Math.max(Player3[0].getY() , Player3[1].getY());
			case 4: return Math.max(Player4[0].getY() , Player4[1].getY());
		}
		return -1;
	}
	
	/*
	 * MinY:
	 * 
	 * @return Integer of player Land Min Y edge.
	 * 
	 */
	public static int MinY (int PlayerNum )  throws Exception {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			throw new Exception("Not a vaild player.");
		switch (PlayerNum) {
			case 1: return Math.min(Player1[0].getY() , Player1[1].getY());
			case 2: return Math.min(Player2[0].getY() , Player2[1].getY());
			case 3: return Math.min(Player3[0].getY() , Player3[1].getY());
			case 4: return Math.min(Player4[0].getY() , Player4[1].getY());
		}
		return -1;
	}
	
	/*
	 * MaxX:
	 * 
	 * @return Integer of player Land Max X edge.
	 * 
	 */
	public static int MaxX (int PlayerNum ) throws StrategoException  {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			throw new GeneralException(GeneralException.GeneralExceptionType.NotValidPlayer);
		switch (PlayerNum) {
			case 1: return Math.max(Player1[0].getX() , Player1[2].getX());
			case 2: return Math.max(Player2[0].getX() , Player2[2].getX());
			case 3: return Math.max(Player3[0].getX() , Player3[2].getX());
			case 4: return Math.max(Player4[0].getX() , Player4[2].getX());
		}
		return -1;
	}
	
	/*
	 * MinX:
	 * 
	 * @return Integer of player Land Min Y edge.
	 * 
	 */
	public static int MinX (int PlayerNum )  throws Exception {
		if (PlayerNum > Consts.MaxNumberOfPlayers || PlayerNum < 1)
			throw new Exception("Not a vaild player.");
		switch (PlayerNum) {
			case 1: return Math.min(Player1[0].getX() , Player1[2].getX());
			case 2: return Math.min(Player2[0].getX() , Player2[2].getX());
			case 3: return Math.min(Player3[0].getX() , Player3[2].getX());
			case 4: return Math.min(Player4[0].getX() , Player4[2].getX());
		}
		return -1;
	}
}